package org.bing.engine.common.message;

import org.bing.engine.common.logging.Log;
import org.bing.engine.common.logging.LogFactory;
import org.bing.engine.utility.helper.GuidGenerator;

public class HandlerAdapter implements Handler {
    protected static final Log logger = LogFactory.getLog(HandlerAdapter.class);

    public Message handle(Message msg) {
        Object body = doHandle(msg);
        Message msgOut = new Message();
        msgOut.setId(GuidGenerator.generate());
        if (!Message.TYPE_IN_ONLY.equals(msg.getType())) {
            msgOut.setBody(body);
        } else {
            msgOut.setType(Message.TYPE_OUT_ONLY);
        }
        msgOut.setTime(System.currentTimeMillis());
        return msgOut;
    }

    protected Object doHandle(Message msg) {
        return msg;
    }
}
